/**
 * 
 */
package core;

import java.util.ArrayList;
import java.util.Collection;

import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * @author Xiaohui
 * 
 */
public class TestJunctions extends TestCase {
	Junctions temp ;
	TimeInterval ti;
	double passingTime = 20.1;
	int jid = 1;
	int[] oids = { 10, 11, 12 };
	double[] junctionxy = { 1.0, 2.0 };
	Junction jc;

	public TestJunctions(String name) {
		super(name);
		jc = new Junction(jid, junctionxy);
		ti = new TimeInterval();
		temp  = new Junctions();
	}

	public void testCollection() {
		Collection collection = new ArrayList();
		collection.add(new Integer(1));
		assertEquals(1, collection.size());
		// assertEquals(2, collection.size());
	}

	public void testJunction() {
		System.out.println("====In testJunction======");

		Junction jc1 = new Junction(jid, junctionxy);
		for (int oid : oids) {
			jc.insertData((int)passingTime, oid);
		}
		assertEquals(1, jc.getId());

		TimeInterval ti2 = new TimeInterval(passingTime);
		for (int oid : oids) {
			jc.insertData((int)passingTime, oid);
		}

		System.out.println(jc);
		assertEquals(jc, jc1);
		// System.out.println(jc.equals(jc1));
		assertEquals(6, jc.getNumPassingObjects());
	}

	public void testJunctions() {
		System.out.println("====In testJunctions======");

		for (int oid : oids) {
			jc.insertData((int)passingTime, oid);
		}
		//test insert
		temp.insert(jc);
		
		System.out.println(jc);
		// test getJuncById
		System.out.println(temp.getJuncById(jid));

		assertEquals(jc, temp.getJuncById(jid));
		assertEquals(1, temp.getSize());
		
		//test delete junction
		temp.delete(jid);
		assertEquals(0, temp.getSize());
	}

	public static TestSuite suite() {
		TestSuite suite = new TestSuite();
		// suite.addTest(new TestJunctions("testCollection"));

		// suite.addTest(new TestJunctions("testJunction"));

		suite.addTest(new TestJunctions("testJunctions"));
		return suite;
	}
}
